home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_pas / ddplus63.zip / COMIO.PAS < prev    next >
Pascal/Delphi Source File  |  1994-03-23  |  6KB  |  250 lines

  1. unit comio;
  2. {$V-,S-,R-}
  3.  
  4. interface
  5.  
  6. uses ddfossil, async2;
  7.  
  8. procedure AsyncSelectPort(n: byte);
  9. procedure AsyncSendChar(ch: char);
  10. procedure AsyncReceiveChar(var ch: char);
  11. function  AsyncCarrierPresent: boolean;
  12. function  AsyncCharPresent: boolean;
  13. procedure AsyncSelectFossil;
  14. procedure AsyncSelectInternal;
  15. procedure AsyncCloseUp;
  16. procedure AsyncCloseCom(cp : byte);
  17. procedure AsyncSetBaud(n: longint);
  18. procedure AsyncSetDTR(state: boolean);
  19. procedure AsyncFlushOutput;
  20. procedure AsyncPurgeOutput;
  21. procedure AsyncSendString(s: string);
  22. procedure AsyncSetFlow(SoftTran,Hard,SoftRecv: boolean);
  23. Procedure AsyncBufferStatus(var Insize,infree,outsize,outfree: word);
  24. Procedure SetUpPorts;
  25. Procedure LoadPorts  (var port1,port2,port3,port4: word;
  26.                       var irq1,irq2,irq3,irq4 : byte);
  27. Procedure ResetPorts (var port1,port2,port3,port4: word;
  28.                       var irq1,irq2,irq3,irq4 : byte);
  29.  
  30. type
  31.  AsyncIoTypes=(Fossil,Internal,Bios);
  32. var
  33.  AsyncIoType: AsyncIotypes;
  34.  {comport: word; }
  35.  initok, X00extOk,Y00extOk  : boolean;
  36.  internalinsize,internaloutsize: word;
  37.  
  38. implementation
  39.  
  40. procedure AsyncSelectPort(n: byte);
  41. var
  42.  b: boolean;
  43. begin;
  44.  comport:=n;
  45.  case AsyncIoType of
  46.    Fossil: If x00extok then
  47.              begin
  48.                port_num:=n-1;
  49.                initok:=true;
  50.               end
  51.             else
  52.               begin
  53.                 async_deinit_fossil;
  54.                 port_num:=n-1;
  55.                 initok:=async_init_fossil;
  56.               end;
  57.             {
  58.             begin
  59.               port_num:=n-1;
  60.               initok:=true;
  61.               async_reset_x00_ext;
  62.             end;
  63.             }
  64.   Internal: begin;
  65.              closeallcoms;
  66.              initok:=opencom(n,InternalInSize,InternalOutSize);
  67.             end;
  68.  end;
  69. end;
  70.  
  71. procedure AsyncSendChar(ch: char);
  72. begin;
  73.  case AsyncIoType of
  74.   Fossil: async_send(ch);
  75.   Internal: begin
  76.               While CTSStat(comport) or RTSstat(comport) do
  77.                 If Not AsyncCarrierPresent then
  78.                      halt;
  79.                ComWriteChw(comport,ch);
  80.             end;
  81.  end;
  82. end;
  83.  
  84. procedure AsyncReceiveChar(var ch: char);
  85. var
  86.  b: boolean;
  87. begin;
  88.  case asyncIotype of
  89.   Fossil: b:=async_receive(ch);
  90.   Internal: ch:=ComReadCh(comport);
  91.  end;
  92. end;
  93.  
  94. function AsyncCarrierPresent: boolean;
  95. begin;
  96.  case asyncIoType of
  97.   Fossil: AsyncCarrierPresent:=async_carrier_present;
  98.   Internal: AsyncCarrierPresent:=DCDStat(comport);
  99.  end;
  100. end;
  101.  
  102. function AsyncCharPresent: boolean;
  103. begin;
  104.  case asyncIoTYpe of
  105.   Fossil: asyncCharPresent:=Async_buffer_check;
  106.   Internal: asynccharpresent:=combufferleft(comport,'I')<>c_insize[comport];
  107.  end;
  108. end;
  109.  
  110. procedure AsyncSelectFossil;
  111. begin;
  112.  AsyncIoType:=Fossil;
  113. end;
  114.  
  115. procedure AsyncCloseUp;
  116. begin;
  117.  case AsyncIoType of
  118.   fossil: Async_deinit_fossil;
  119.   internal: closeallcoms;
  120.  end;
  121. end;
  122.  
  123. procedure AsyncCloseCom;
  124. begin;
  125.  case AsyncIoType of
  126.   fossil:   Async_deinit_fossil;
  127.   {
  128.     async_reset_x00_ext(n);
  129.   }
  130.   internal: closecom(cp);
  131.  end;
  132. end;
  133.  
  134. procedure AsyncSetBaud(n: longint);
  135. begin;
  136.  case asynciotype of
  137.   fossil:   If not X00extok then async_set_baud(n);
  138.   {
  139.     async_set_x00_ext(n);
  140.   }
  141.   internal: comparams(comport,n,8,'N',1);
  142.  end;
  143. end;
  144.  
  145. procedure AsyncSelectInternal;
  146. begin;
  147.  AsyncIOType:=Internal;
  148. end;
  149.  
  150. procedure AsyncSetDTR(state: boolean);
  151. begin;
  152.  case AsyncIOType of
  153.   Fossil:   async_set_dtr(state);
  154.   Internal: SetDTR(comport,state);
  155.  end;
  156. end;
  157.  
  158. procedure AsyncFlushOutput;
  159. begin;
  160.  case AsyncIOType of
  161.   Fossil:   async_flush_output;
  162.   Internal: ComWaitForClear(comport);
  163.  end;
  164. end;
  165.  
  166. procedure AsyncPurgeOutput;
  167. begin;
  168.  case AsyncIOType of
  169.   Fossil:   async_purge_output;
  170.   Internal: ClearCom(comport,'O');
  171.  end;
  172. end;
  173.  
  174. procedure AsyncSendString(s: string);
  175. var
  176.  a: integer;
  177. begin;
  178.  for a:=1 to length(s) do AsyncSendChar(s[a]);
  179. end;
  180.  
  181. procedure AsyncSetFlow(SoftTran,Hard,SoftRecv: boolean);
  182. begin;
  183.  {*srl}
  184.  case AsyncIOType of
  185.   Fossil:   async_set_flow(softtran,hard,softrecv);
  186.   Internal: begin;
  187.               SetCTSMode(comport,hard);
  188.               SetRTSMode(comport,hard,C_RTSOn[comport],C_RTSOff[comport]);
  189.               SoftHandShake(comport,softtran,'A','A');
  190.              end;
  191.  end;
  192. end;
  193.  
  194. Procedure AsyncBufferStatus(var Insize,infree,outsize,outfree: word);
  195. begin;
  196.  case asynciotype of
  197.   fossil: async_buffer_Status(insize,infree,outsize,outfree);
  198.   internal: begin;
  199.              insize:=internalinsize;
  200.              outsize:=internaloutsize;
  201.              infree:=combufferleft(comport,'I');
  202.              outfree:=combufferleft(comport,'O');
  203.             end;
  204.  end;
  205. end;
  206.  
  207. Procedure SetUpPorts;
  208. var
  209.   i : byte;
  210. begin
  211.  for i := 1 to 4 do
  212.     begin
  213.       C_PortAddr[i] := D_PortAddr[i];
  214.       C_PortInt[i]  := D_PortInt[i];
  215.     end;
  216. end;
  217.  
  218. Procedure LoadPorts (var port1,port2,port3,port4: word;
  219.                      var irq1,irq2,irq3,irq4 : byte);
  220. begin
  221.  port1 :=  D_PortAddr[1];
  222.  irq1  :=  D_PortInt[1];
  223.  port2 :=  D_PortAddr[2];
  224.  irq2  :=  D_PortInt[2];
  225.  port3 :=  D_PortAddr[3];
  226.  irq3  :=  D_PortInt[3];
  227.  port4 :=  D_PortAddr[4];
  228.  irq4  :=  D_PortInt[4];
  229. end;
  230.  
  231. Procedure ResetPorts (var port1,port2,port3,port4: word;
  232.                       var irq1,irq2,irq3,irq4 : byte);
  233. begin
  234.   C_PortAddr[1] := port1;
  235.   C_PortInt[1]  := irq1;
  236.   C_PortAddr[2] := port2;
  237.   C_PortInt[2]  := irq2;
  238.   C_PortAddr[3] := port3;
  239.   C_PortInt[3]  := irq3;
  240.   C_PortAddr[4] := port4;
  241.   C_PortInt[4]  := irq4;
  242. end;
  243.  
  244. begin;
  245.  AsyncIoType:=Internal;
  246.  comport:=1;
  247.  internalinsize :=2048;
  248.  internaloutsize:=2048;
  249. end.
  250.